//
//  ViewController.m
//  UI23_02_NSNotificationCenter
//
//  Created by 李劲成 on 16/4/11.
//  Copyright © 2016年 ljc. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UITextField *textField;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bottom;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self notiCenter];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)notiCenter {
    
    // 获取通知中心.
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(handleTextField:) name:UIKeyboardWillShowNotification object:nil];
}

// 通知事件
- (void)handleTextField:(NSNotification *)noti {
    NSLog(@"%@", noti);
    NSDictionary *dic = noti.userInfo;
    NSValue *rect  = [dic objectForKey:@"UIKeyboardFrameEndUserInfoKey"];
    CGFloat h = rect.CGRectValue.size.height;
    NSLog(@"%f", h);
    
    // 重新计算 textField 位置.
    
    self.textField.translatesAutoresizingMaskIntoConstraints = NO;
    // 约束改变
    self.bottom.constant = 400;
    
    [UIView animateWithDuration:0.1 animations:^{
        
        // 重新布局
        [self.view layoutIfNeeded];
        
    }];
    
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
